using Circus.CodeEditor;
using Circus.Syntax;
using Circus.Syntax.CodeCompletion;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Circus.CodeEditor.CodeCompletion
{
	[DesignTimeVisible(false), ToolboxItem(false)]
	public class CodeCompletionWindow : Form, ICodeCompletionWindow
	{
		internal class PopupNativeWindow : NativeWindow, IDisposable
		{
			private IList<ICodeCompletionWindow> popups;
			protected override void WndProc(ref Message m)
			{
				int msg = m.Msg;
				if (msg == 134)
				{
					if (m.WParam == IntPtr.Zero)
					{
						foreach (ICodeCompletionWindow current in this.popups)
						{
							if (current.IsVisible)
							{
								m.Result = (IntPtr)1;
								return;
							}
						}
					}
				}
				base.WndProc(ref m);
			}
			public PopupNativeWindow(IntPtr handle)
			{
				this.popups = new List<ICodeCompletionWindow>();
				base.AssignHandle(handle);
			}
			~PopupNativeWindow()
			{
				this.Dispose(false);
			}
			public void Add(ICodeCompletionWindow popup)
			{
				this.popups.Add(popup);
			}
			public void Remove(ICodeCompletionWindow popup)
			{
				this.popups.Remove(popup);
			}
			public virtual void Dispose(bool disposing)
			{
				if (disposing)
				{
					this.popups.Clear();
					this.ReleaseHandle();
				}
			}
			public void Dispose()
			{
				this.Dispose(true);
				GC.SuppressFinalize(this);
			}
		}
		internal class PopupWnd : IDisposable
		{
			private CodeCompletionWindow.PopupNativeWindow nativeWindow;
			private CodeCompletionWindow.PopupNativeWindow mdiNativeWindow;
			private ICodeCompletionWindow popup;
			public ICodeCompletionWindow Popup
			{
				get
				{
					return this.popup;
				}
			}
			private CodeCompletionWindow.PopupNativeWindow GetNativeWindow(IntPtr handle)
			{
				NativeWindow nativeWindow = NativeWindow.FromHandle(handle);
				CodeCompletionWindow.PopupNativeWindow result;
				if (nativeWindow is CodeCompletionWindow.PopupNativeWindow)
				{
					result = (CodeCompletionWindow.PopupNativeWindow)nativeWindow;
				}
				else
				{
					result = new CodeCompletionWindow.PopupNativeWindow(handle);
				}
				return result;
			}
			public PopupWnd(ICodeCompletionWindow popup, Control popupParent)
			{
				this.popup = popup;
				if (popupParent != null && popupParent.IsHandleCreated)
				{
					this.nativeWindow = this.GetNativeWindow(popupParent.Handle);
					this.nativeWindow.Add(this.Popup);
				}
				if (popupParent is Form && ((Form)popupParent).IsMdiChild)
				{
					Form mdiParent = ((Form)popupParent).MdiParent;
					if (mdiParent != null && mdiParent.IsHandleCreated)
					{
						this.mdiNativeWindow = this.GetNativeWindow(mdiParent.Handle);
						this.mdiNativeWindow.Add(this.Popup);
					}
				}
			}
			~PopupWnd()
			{
				this.Dispose(false);
			}
			public void Dispose()
			{
				this.Dispose(true);
				GC.SuppressFinalize(this);
			}
			protected virtual void Dispose(bool disposing)
			{
				if (disposing)
				{
					if (this.nativeWindow != null)
					{
						this.nativeWindow.Remove(this.Popup);
						this.nativeWindow.Dispose();
						this.nativeWindow = null;
					}
					if (this.mdiNativeWindow != null)
					{
						this.mdiNativeWindow.Remove(this.Popup);
						this.mdiNativeWindow.Dispose();
						this.mdiNativeWindow = null;
					}
				}
			}
		}
		public class PopupHookManager
		{
			private static bool inMouseHook = false;
			private static IntPtr mouseHookHandle = IntPtr.Zero;
			private static HookHandler mouseHookProc;
			private static Point mousePos;
			private static IList<CodeCompletionWindow.PopupWnd> Popups = new List<CodeCompletionWindow.PopupWnd>();
			public static int PopupCount
			{
				get
				{
					return CodeCompletionWindow.PopupHookManager.Popups.Count;
				}
			}
			internal static bool NeedCloseOnLostFocus(ICodeCompletionWindow wnd)
			{
				bool result;
				if ((wnd.CompletionFlags & CodeCompletionFlags.CloseOnLostFocus) == CodeCompletionFlags.None)
				{
					result = false;
				}
				else
				{
					foreach (CodeCompletionWindow.PopupWnd current in CodeCompletionWindow.PopupHookManager.Popups)
					{
						ICodeCompletionWindow popup = current.Popup;
						if (popup != null && popup.IsVisible && popup.IsFocused)
						{
							result = false;
							return result;
						}
					}
					result = true;
				}
				return result;
			}
			internal static void CheckMouse(Control control, Point mousePos, bool mouseMove)
			{
				for (int i = CodeCompletionWindow.PopupHookManager.Popups.Count - 1; i >= 0; i--)
				{
					CodeCompletionWindow.PopupWnd popupWnd = CodeCompletionWindow.PopupHookManager.Popups[i];
                    CodeCompletionWindow codeCompletionWindow = (CodeCompletionWindow)popupWnd.Popup;
					var control2 = codeCompletionWindow;
					if (control2 != null && control2.Created && control2.Visible)
					{
						Control control3 = control2.FindForm();
						if (control3 != null && (!control3.Contains(control) && control3 != control && codeCompletionWindow != control) && !codeCompletionWindow.ContainsControl(control))
						{
							if (mouseMove && codeCompletionWindow.OwnerControl != null && (codeCompletionWindow.CompletionFlags & CodeCompletionFlags.CloseOnMouseLeave) != CodeCompletionFlags.None)
							{
								Control ownerControl = codeCompletionWindow.OwnerControl;
								Rectangle rectangle = new Rectangle(0, 0, ownerControl.Width, ownerControl.Height);
								if (!control2.Bounds.Contains(mousePos) && !rectangle.Contains(ownerControl.PointToClient(mousePos)))
								{
									codeCompletionWindow.CloseDelayed(false);
								}
							}
							else
							{
								if (!mouseMove && !control2.Bounds.Contains(mousePos))
								{
									codeCompletionWindow.CloseDelayed(false);
								}
							}
						}
					}
				}
			}
			internal static void InstallHook()
			{
				CodeCompletionWindow.PopupHookManager.mouseHookProc = new HookHandler(CodeCompletionWindow.PopupHookManager.MouseHook);
				CodeCompletionWindow.PopupHookManager.mouseHookHandle = OSUtils.SetMouseHook(CodeCompletionWindow.PopupHookManager.mouseHookProc);
				Application.ApplicationExit += new EventHandler(CodeCompletionWindow.PopupHookManager.OnApplicationExit);
			}
			internal static void RemoveHook()
			{
				if (CodeCompletionWindow.PopupHookManager.mouseHookHandle != IntPtr.Zero)
				{
					Application.ApplicationExit -= new EventHandler(CodeCompletionWindow.PopupHookManager.OnApplicationExit);
					OSUtils.ReleaseHook(CodeCompletionWindow.PopupHookManager.mouseHookHandle);
					CodeCompletionWindow.PopupHookManager.mouseHookHandle = IntPtr.Zero;
					CodeCompletionWindow.PopupHookManager.mouseHookProc = null;
				}
			}
			internal static void OnApplicationExit(object sender, EventArgs e)
			{
				CodeCompletionWindow.PopupHookManager.RemoveHook();
			}
			private static IntPtr MouseHook(int ncode, IntPtr wParam, IntPtr lParam)
			{
				IntPtr result;
				if (ncode == 0)
				{
					if (CodeCompletionWindow.PopupHookManager.inMouseHook || !(lParam != IntPtr.Zero))
					{
						result = OSUtils.CallNextHook(CodeCompletionWindow.PopupHookManager.mouseHookHandle, ncode, wParam, lParam);
						return result;
					}
					Point point;
					IntPtr hWnd = OSUtils.GetMouseHookHandle(lParam, out point);
					try
					{
						CodeCompletionWindow.PopupHookManager.inMouseHook = true;
						CodeCompletionWindow.PopupHookManager.FilterMouseMessage(wParam.ToInt32(), hWnd);
					}
					finally
					{
						CodeCompletionWindow.PopupHookManager.inMouseHook = false;
					}
				}
				result = OSUtils.CallNextHook(CodeCompletionWindow.PopupHookManager.mouseHookHandle, ncode, wParam, lParam);
				return result;
			}
			internal static bool IsSignificantMouseMove(Point pt)
			{
				return Math.Abs(pt.X - CodeCompletionWindow.PopupHookManager.mousePos.X) > 5 || Math.Abs(pt.Y - CodeCompletionWindow.PopupHookManager.mousePos.Y) > 5;
			}
			internal static void FilterMouseMessage(int msg, IntPtr hWnd)
			{
				Point mousePosition = Control.MousePosition;
				if (OSUtils.IsMouseMsg(msg) || (msg == 512 && CodeCompletionWindow.PopupHookManager.IsSignificantMouseMove(mousePosition)))
				{
					if (msg == 512)
					{
						CodeCompletionWindow.PopupHookManager.mousePos = mousePosition;
					}
					CodeCompletionWindow.PopupHookManager.CheckMouse(Control.FromHandle(hWnd), mousePosition, msg == 512);
				}
			}
			internal static void PopupClosed(ICodeCompletionWindow popup)
			{
				for (int i = CodeCompletionWindow.PopupHookManager.Popups.Count - 1; i >= 0; i--)
				{
					CodeCompletionWindow.PopupWnd popupWnd = CodeCompletionWindow.PopupHookManager.Popups[i];
					if (popupWnd.Popup == popup)
					{
						popupWnd.Dispose();
						CodeCompletionWindow.PopupHookManager.Popups.RemoveAt(i);
						break;
					}
				}
				if (CodeCompletionWindow.PopupHookManager.Popups.Count == 0)
				{
					CodeCompletionWindow.PopupHookManager.RemoveHook();
				}
			}
			internal static void PopupShowing(ICodeCompletionWindow popup)
			{
				CodeCompletionWindow.PopupHookManager.Popups.Add(new CodeCompletionWindow.PopupWnd(popup, popup.OwnerControl.FindForm()));
				if (CodeCompletionWindow.PopupHookManager.mouseHookHandle == IntPtr.Zero)
				{
					CodeCompletionWindow.PopupHookManager.InstallHook();
				}
			}
		}
		private CodeCompletionFlags completionFlags = EditConsts.DefaultCodeCompletionFlags;
		private ImageList images;
		private bool sizeable;
		private ICodeCompletionProvider provider;
		private Point startPos;
		private Point endPos;
		private Point displayPos;
		private Control ownerControl;
		private Control popupControl;
		private Control prevFocused;
		protected bool showing;
	    public event ClosePopupEvent ClosePopup;

	    public event ShowPopupEvent ShowPopup;
	    public event KeyPreviewEvent KeyPreviewEvent;
		protected override CreateParams CreateParams
		{
			get
			{
				uint num = 2147483648u;
				CreateParams createParams = base.CreateParams;
				createParams.Style |= (int)num;
				return createParams;
			}
		}
		public override bool AutoSize
		{
			get
			{
				return base.AutoSize;
			}
			set
			{
				if (base.AutoSize != value)
				{
					base.AutoSize = value;
					this.OnAutoSizeChanged();
				}
			}
		}
		public virtual Control PopupControl
		{
			get
			{
				return this.popupControl;
			}
		}
		public virtual ICodeCompletionProvider Provider
		{
			get
			{
				return this.provider;
			}
			set
			{
				if (this.provider != value)
				{
					this.provider = value;
					this.SetProvider(value);
				}
			}
		}
		public virtual bool IsFocused
		{
			get
			{
				return this.Focused || this.popupControl.Focused;
			}
		}
		public virtual bool IsVisible
		{
			get
			{
				return base.Visible;
			}
		}
		public virtual bool Sizeable
		{
			get
			{
				return this.sizeable;
			}
			set
			{
				if (this.sizeable != value)
				{
					this.sizeable = value;
					this.OnSizeableChanged();
				}
			}
		}
		public virtual ImageList Images
		{
			get
			{
				return this.images;
			}
			set
			{
				if (this.images != value)
				{
					this.images = value;
					this.OnImagesChanged();
				}
			}
		}
		public virtual CodeCompletionFlags CompletionFlags
		{
			get
			{
				return this.completionFlags;
			}
			set
			{
				if (this.completionFlags != value)
				{
					this.completionFlags = value;
					this.OnCompletionFlagsChanged();
				}
			}
		}
		public virtual Control OwnerControl
		{
			get
			{
				return this.ownerControl;
			}
			set
			{
				if (this.ownerControl != value)
				{
					this.ownerControl = value;
					this.OnOwnerControlChanged();
				}
			}
		}
		public virtual Point StartPos
		{
			get
			{
				return this.startPos;
			}
			set
			{
				if (this.startPos != value)
				{
					this.startPos = value;
					this.OnStartPosChanged();
				}
			}
		}
		public virtual Point EndPos
		{
			get
			{
				return this.endPos;
			}
			set
			{
				if (this.endPos != value)
				{
					this.endPos = value;
					this.OnEndPosChanged();
				}
			}
		}
		public virtual Point DisplayPos
		{
			get
			{
				return this.displayPos;
			}
			set
			{
				if (this.displayPos != value)
				{
					this.displayPos = value;
					this.OnDisplayPosChanged();
				}
			}
		}
		private Form GetParentForm(Control c)
		{
			Form result;
			while (c != null)
			{
				if (c is Form)
				{
					result = (Form)c;
					return result;
				}
				c = c.Parent;
			}
			result = null;
			return result;
		}
		private bool IsPositionValid()
		{
			bool flag = true;
			CodeEditor syntaxEdit = this.GetSyntaxEdit();
			if (syntaxEdit != null)
			{
				Point position = syntaxEdit.Position;
				if (this.startPos.Y >= 0)
				{
					flag = (position.Y > this.startPos.Y || (position.Y == this.startPos.Y && position.X >= this.startPos.X));
				}
				if (flag && this.endPos.Y >= 0)
				{
					flag = (position.Y < this.endPos.Y || (position.Y == this.endPos.Y && position.X <= this.endPos.X));
				}
			}
			return flag;
		}
		protected CodeEditor GetSyntaxEdit()
		{
			return (this.ownerControl is CodeEditor) ? ((CodeEditor)this.ownerControl) : null;
		}
		protected virtual void UpdateAutoSize()
		{
		}
		protected virtual bool OnProcessKeyPreview(ref Message m)
		{
			bool result;
			if (this.KeyPreviewEvent != null)
			{
				KeyPreviewEventArgs keyPreviewEventArgs = new KeyPreviewEventArgs(m);
				this.KeyPreviewEvent(this, keyPreviewEventArgs);
				result = keyPreviewEventArgs.Handled;
			}
			else
			{
				result = false;
			}
			return result;
		}
		protected virtual bool IsPopupControlFocused()
		{
			return this.PopupControl.Focused;
		}
		protected virtual bool NeedCloseOnLostFocus()
		{
			return CodeCompletionWindow.PopupHookManager.NeedCloseOnLostFocus(this);
		}
		protected virtual void DoProcessKeyMessage(ref Message m)
		{
			CodeEditor syntaxEdit = this.GetSyntaxEdit();
			if (syntaxEdit != null)
			{
				Message message = default(Message);
				message.HWnd = syntaxEdit.Handle;
				message.LParam = m.LParam;
				message.Msg = m.Msg;
				message.Result = m.Result;
				message.WParam = m.WParam;
				syntaxEdit.ProcessKeyMsg(ref message);
				m.Result = message.Result;
			}
		}
		protected void DoLostFocus(object sender, EventArgs e)
		{
			if (!this.showing && this.NeedCloseOnLostFocus())
			{
				this.Close(false, false);
				CodeEditor syntaxEdit = this.GetSyntaxEdit();
				if (syntaxEdit != null && !syntaxEdit.Focused)
				{
					syntaxEdit.KillFocus();
				}
			}
		}
		protected void DoClick(object sender, EventArgs e)
		{
			if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnClick) != CodeCompletionFlags.None)
			{
				this.Close(true);
			}
		}
		protected virtual Control CreatePopupControl()
		{
			return null;
		}
		protected virtual int GetSelectedIndex()
		{
			return -1;
		}
		protected void DoDoubleClick(object sender, EventArgs e)
		{
			if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnDblClick) != CodeCompletionFlags.None)
			{
				this.Close(true);
			}
		}
		protected virtual void CheckPositionValid()
		{
			if ((this.CompletionFlags & CodeCompletionFlags.KeepActive) == CodeCompletionFlags.None && !this.IsPositionValid())
			{
				this.Close(false);
			}
		}
		protected virtual void DoShow(Point position)
		{
			if (this.popupControl.Visible)
			{
				base.Location = position;
			}
			else
			{
				this.prevFocused = null;
				if (this.ownerControl is CodeEditor)
				{
					if (this.ownerControl.Focused || ((CodeEditor)this.ownerControl).CodeCompletionWindowFocused(out this.prevFocused))
					{
						if (this.prevFocused == null)
						{
							this.prevFocused = this.ownerControl;
						}
					}
				}
				else
				{
					this.prevFocused = ((this.ownerControl != null && this.ownerControl.Focused) ? this.ownerControl : null);
				}
				base.Location = position;
				OSUtils.ShowWindowTopMost(base.Handle, position.X, position.Y, base.Width, base.Height);
				base.Visible = true;
				if (this.popupControl.CanFocus)
				{
					this.popupControl.Focus();
				}
			}
		}
		protected virtual void DoHide()
		{
			base.Visible = false;
		}
		protected virtual void OnShowPopup(ShowingEventArgs args)
		{
			if (this.ShowPopup != null)
			{
				this.ShowPopup(this, args);
			}
		}
		protected virtual void OnClosePopup(ClosingEventArgs args)
		{
			args.StartPosition = this.startPos;
			args.EndPosition = this.endPos;
			if (this.Provider != null)
			{
				if (args.KeyChar == ' ' && this.ownerControl != null && this.ownerControl.CanFocus)
				{
					this.ownerControl.Focus();
				}
				this.Provider.OnClosePopup(this, args);
				if (args.Accepted && args.Handled)
				{
					this.Provider = args.Provider;
					return;
				}
			}
			if (this.ClosePopup != null)
			{
				this.ClosePopup(this, args);
			}
		}
		protected virtual void CheckMouseLeave(object sender, EventArgs e)
		{
			if (base.Visible && (this.CompletionFlags & CodeCompletionFlags.CloseOnMouseLeave) != CodeCompletionFlags.None && (this.ownerControl == null || !this.ownerControl.Bounds.Contains(Control.MousePosition) || (sender == this.ownerControl && !base.Bounds.Contains(Control.MousePosition))))
			{
				this.CloseDelayed(false);
			}
		}
		protected virtual void CodeEditDisposed()
		{
		}
		protected override bool ProcessKeyPreview(ref Message m)
		{
			Keys keys = Keys.None;
			bool result;
			if (m.Msg == 256 || m.Msg == 260)
			{
				keys = (Keys)(m.WParam.ToInt32() & 65535);
				Keys keys2 = keys;
				if (keys2 <= Keys.Return)
				{
					if (keys2 != Keys.Tab)
					{
						if (keys2 == Keys.Return)
						{
							if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnEnter) != CodeCompletionFlags.None)
							{
								this.Close(true, '\r');
								result = true;
								return result;
							}
						}
					}
					else
					{
						if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnTab) != CodeCompletionFlags.None)
						{
							this.Close(true, '\t');
							result = true;
							return result;
						}
					}
				}
				else
				{
					if (keys2 != Keys.Escape)
					{
						if (keys2 == Keys.Space)
						{
							if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnSpace) != CodeCompletionFlags.None)
							{
								this.Close(true, ' ');
								result = true;
								return result;
							}
						}
					}
					else
					{
						if ((this.CompletionFlags & CodeCompletionFlags.CloseOnEscape) != CodeCompletionFlags.None)
						{
							this.Close(false, '\u001b');
							result = true;
							return result;
						}
					}
				}
			}
			if (m.Msg == 258 && m.WParam.ToInt32() == 32)
			{
				if ((this.CompletionFlags & CodeCompletionFlags.AcceptOnSpace) != CodeCompletionFlags.None)
				{
					this.Close(true, ' ');
					result = true;
					return result;
				}
			}
			this.DoProcessKeyMessage(ref m);
			this.CheckPositionValid();
			result = ((((m.Msg == 258 && m.WParam.ToInt32() != 27 && m.WParam.ToInt32() != 13) || keys == Keys.Back) && this.PerformSearch()) || base.ProcessKeyPreview(ref m));
			return result;
		}
		protected override void WndProc(ref Message m)
		{
			int msg = m.Msg;
			if (msg == 1025)
			{
				this.Close(m.WParam != IntPtr.Zero, false);
			}
			base.WndProc(ref m);
		}
		protected virtual void OnSizeableChanged()
		{
			if (this.sizeable)
			{
				base.FormBorderStyle = FormBorderStyle.Sizable;
			}
			else
			{
				base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			}
		}
		protected virtual void OnImagesChanged()
		{
		}
		protected virtual void OnCompletionFlagsChanged()
		{
		}
		protected virtual void OnOwnerControlChanged()
		{
		}
		protected virtual void OnStartPosChanged()
		{
		}
		protected virtual void OnEndPosChanged()
		{
		}
		protected virtual void OnDisplayPosChanged()
		{
		}
		protected virtual void OnAutoSizeChanged()
		{
			if (this.AutoSize)
			{
				this.UpdateAutoSize();
			}
		}
		protected virtual void SetProvider(ICodeCompletionProvider provider)
		{
		}
		public CodeCompletionWindow()
		{
			this.MinimumSize = new Size(this.Font.Height + 2, this.Font.Height + 2);
			base.SizeGripStyle = SizeGripStyle.Hide;
			base.StartPosition = FormStartPosition.Manual;
			base.FormBorderStyle = FormBorderStyle.FixedSingle;
			base.Width = 200;
			base.Height = 200;
			base.ShowInTaskbar = false;
			base.ControlBox = false;
			this.BackColor = Consts.DefaultControlBackColor;
			base.SetStyle(ControlStyles.ResizeRedraw, true);
			base.TopLevel = true;
			base.DoubleClick += new EventHandler(this.DoDoubleClick);
			base.Click += new EventHandler(this.DoClick);
			base.LostFocus += new EventHandler(this.DoLostFocus);
			this.popupControl = this.CreatePopupControl();
			if (this.popupControl != null)
			{
				this.popupControl.DoubleClick += new EventHandler(this.DoDoubleClick);
				this.popupControl.Click += new EventHandler(this.DoClick);
				this.popupControl.LostFocus += new EventHandler(this.DoLostFocus);
				this.popupControl.Parent = this;
				this.popupControl.Dock = DockStyle.Fill;
			}
			this.AutoSize = true;
		}
		public CodeCompletionWindow(CodeEditor owner) : this()
		{
			this.ownerControl = (Control)owner;
			base.Owner = this.GetParentForm((Control)owner);
		}
		protected virtual void Close(bool accept, bool setFocus, char keyChar)
		{
			if (base.Visible)
			{
				if (this.Provider != null)
				{
					this.Provider.SelIndex = this.GetSelectedIndex();
				}
				ClosingEventArgs closingEventArgs = new ClosingEventArgs(accept, this.Provider);
				closingEventArgs.UseIndent = (this.Provider != null && this.Provider.UseIndent);
				closingEventArgs.Text = ((this.Provider != null && this.Provider.ColumnCount != 0 && this.Provider.SelIndex >= 0 && this.Provider.SelIndex < this.Provider.Count) ? this.Provider.GetText(this.Provider.SelIndex) : string.Empty);
				closingEventArgs.KeyChar = keyChar;
				this.OnClosePopup(closingEventArgs);
				if (!closingEventArgs.Handled)
				{
					CodeCompletionWindow.PopupHookManager.PopupClosed(this);
					this.DoHide();
					if (setFocus && this.prevFocused != null && this.prevFocused.CanFocus)
					{
						this.prevFocused.Focus();
					}
				}
			}
		}
		public virtual void Close(bool accept, char keyChar)
		{
			this.Close(accept, true, keyChar);
		}
		public virtual void Close(bool accept, bool setFocus)
		{
			this.Close(accept, setFocus, '\0');
		}
		public virtual void PositionChanged(int x, int y, int deltaX, int deltaY)
		{
			if (base.Visible)
			{
				Range.UpdatePos(x, y, deltaX, deltaY, ref this.endPos, false);
			}
		}
		public virtual void Popup()
		{
			this.PopupAt(Control.MousePosition);
		}
		public virtual void PopupAt(int x, int y)
		{
			this.PopupAt(new Point(x, y));
		}
		public virtual void PopupAt(Point position)
		{
			if (this.Provider != null)
			{
				ICodeCompletionProvider codeCompletionProvider = this.Provider;
				ShowingEventArgs showingEventArgs = new ShowingEventArgs(this.Provider);
				codeCompletionProvider.OnShowPopup(this, showingEventArgs);
				this.OnShowPopup(showingEventArgs);
				if (!showingEventArgs.NeedShow)
				{
					return;
				}
			}
			this.showing = true;
			try
			{
				if ((this.completionFlags & CodeCompletionFlags.FeetToScreen) > CodeCompletionFlags.None)
				{
					this.EnsureVisible(ref position);
				}
				CodeCompletionWindow.PopupHookManager.PopupClosed(this);
				CodeCompletionWindow.PopupHookManager.PopupShowing(this);
				this.DoShow(position);
			}
			finally
			{
				this.showing = false;
			}
		}
		public virtual void Close(bool accept)
		{
			this.Close(accept, true);
		}
		public virtual void CloseDelayed(bool accept)
		{
			if (base.IsHandleCreated)
			{
				OSUtils.PostMessage(base.Handle, 1025, accept ? new IntPtr(1) : IntPtr.Zero, IntPtr.Zero);
			}
			else
			{
				this.Close(accept);
			}
		}
		public virtual void EnsureVisible(ref Point position)
		{
			Rectangle workingArea = Screen.GetWorkingArea(position);
			Rectangle rect = new Rectangle(position, base.Bounds.Size);
			if (!workingArea.Contains(rect))
			{
				if (rect.X < workingArea.Left)
				{
					position.X = workingArea.Left;
				}
				else
				{
					if (rect.Right > workingArea.Right)
					{
						position.X = workingArea.Right - rect.Width;
					}
				}
				if (rect.Y < workingArea.Top)
				{
					position.Y = workingArea.Top;
				}
				else
				{
					if (rect.Bottom > workingArea.Bottom)
					{
						CodeEditor syntaxEdit = this.GetSyntaxEdit();
						int num = (syntaxEdit != null) ? syntaxEdit.Painter.FontHeight : base.FontHeight;
						position.Y = Math.Min(position.Y - rect.Height - num, workingArea.Bottom - rect.Height);
					}
				}
			}
		}
		public virtual void ResetContent()
		{
		}
		public virtual void ResetSizeable()
		{
			this.Sizeable = false;
		}
		public virtual void ResetAutoSize()
		{
			this.AutoSize = true;
		}
		public virtual void ResetCodeCompletionFlags()
		{
			this.CompletionFlags = EditConsts.DefaultCodeCompletionFlags;
		}
		public virtual bool PerformSearch()
		{
			return false;
		}
		public virtual bool ContainsControl(Control control)
		{
			return control != null && base.Contains(control);
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				base.DoubleClick -= new EventHandler(this.DoDoubleClick);
				base.Click -= new EventHandler(this.DoClick);
				base.LostFocus -= new EventHandler(this.DoLostFocus);
				if (this.popupControl != null)
				{
					this.popupControl.LostFocus -= new EventHandler(this.DoLostFocus);
					this.popupControl.Click -= new EventHandler(this.DoClick);
					this.popupControl.DoubleClick -= new EventHandler(this.DoDoubleClick);
					this.popupControl = null;
				}
				base.Owner = null;
			}
			base.Dispose(disposing);
		}
	
	}
}
